package com.junmo.fanbizhidemo.demoview;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.Toast;

import com.junmo.fanbizhidemo.R;
import com.junmo.fanbizhidemo.view.pop.SelectPicPopupWindow;

import butterknife.BindView;
import butterknife.ButterKnife;

public class JhActivity extends Activity {

    @BindView(R.id.button_txt)
    Button buttonTxt;
    @BindView(R.id.dibu)
    Button dibu;

    private PopupWindow mPopupWindow;
    View popupView;


    SelectPicPopupWindow menuWindow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jh);
        ButterKnife.bind(this);
        popupView = getLayoutInflater().inflate(R.layout.pop_layout, null);

        mPopupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        mPopupWindow.setTouchable(true);
        mPopupWindow.setOutsideTouchable(true);
        mPopupWindow.setBackgroundDrawable(new BitmapDrawable(getResources(), (Bitmap) null));

        buttonTxt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPopupWindow.showAsDropDown(v);
            }
        });

        dibu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                menuWindow = new SelectPicPopupWindow(JhActivity.this, itemsOnClick);

                //显示窗口
                menuWindow.showAtLocation(JhActivity.this.findViewById(R.id.main), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); //设置layout在PopupWindow中显示的位置

            }
        });
    }

    //为弹出窗口实现监听类
    private View.OnClickListener itemsOnClick = new View.OnClickListener() {

        public void onClick(View v) {
            menuWindow.dismiss();
            switch (v.getId()) {
                case R.id.alert_a:
                    Toast.makeText(JhActivity.this, "aa", Toast.LENGTH_SHORT).show();
                    break;
                case R.id.alert_b:
                    Toast.makeText(JhActivity.this, "bb", Toast.LENGTH_SHORT).show();
                    break;
                case R.id.alert_c:
                    Toast.makeText(JhActivity.this, "cc", Toast.LENGTH_SHORT).show();
                    break;

                default:
                    break;
            }


        }

    };

}
